package com.dbdata.move.service;

import com.dbdata.move.Utils;
import com.dbdata.move.dao.TaskDocDao;
import com.dbdata.move.model.*;
import com.dbdata.move.vo.UserInfo;
import com.wksc.commons.utils.date.DateFormatEnum;
import com.wksc.commons.utils.date.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.text.ParseException;
import java.util.*;

/**
 * TODO
 *
 * @author ChengJianLong
 */
@Service
public class TaskDocService {
    private static final Logger LOGGER = LoggerFactory.getLogger(AirLineService.class);

    @Autowired
    private TaskDocDao dao;

    private Map<Integer, Ins> insMap = new HashMap<Integer, Ins>();

    private Map<Integer, Stu> stuMap = new HashMap<Integer, Stu>();

    private Map<String, Long> teacherMap = new HashMap<String, Long>();

    private Map<String, Long> studentMap = new HashMap<String, Long>();

    private Map<String, AirplaneNumber> feijiMap = new HashMap<String, AirplaneNumber>();

    private Map<String, AirplaneNumber> monijiMap = new HashMap<String, AirplaneNumber>();

    private Map<String, Airport> airportMap = new HashMap<String, Airport>();

    private Map<Byte, FlightCharacter> flightCharacterMap = new HashMap<Byte, FlightCharacter>();

    public void getUserDataMap() {
        List<Ins> insList = dao.listIns();
        this.setInsMap(insList);
        List<Stu> stuList = dao.listStu();
        this.setStuMap(stuList);
        List<UserInfo> teacherList = dao.listUserInfo((byte) 1);
        this.setTeacherMap(teacherList);
        List<UserInfo> studentList = dao.listUserInfo((byte) 2);
        this.setStudentMap(studentList);
        List<UserInfo> foreignStudentList = dao.listUserInfoForeign((byte) 2);
        this.setStudentMap(foreignStudentList);
        List<AirplaneNumber> feijiList = dao.listAirplaneNumber((byte) 0);
        this.setFeijiMap(feijiList);
        List<AirplaneNumber> monijiList = dao.listAirplaneNumber((byte) 1);
        this.setMonijiMap(monijiList);
        List<Airport> airportList = dao.listAirport();
        this.setAirportMap(airportList);
        List<FlightCharacter> flightCharacterList = dao.listFlightCharacter();
        this.setFlightCharacterMap(flightCharacterList);
    }

    private void setFlightCharacterMap(List<FlightCharacter> flightCharacterList) {
        for (FlightCharacter flightCharacter : flightCharacterList) {
            if (flightCharacter.getFlightCharacterSign() == (byte) 10) {
                flightCharacterMap.put((byte) 17, flightCharacter);
            }
            flightCharacterMap.put(flightCharacter.getFlightCharacterSign(), flightCharacter);
        }
    }

    private void setInsMap(List<Ins> insList) {
        for (Ins ins : insList)
            insMap.put(ins.getUserId(), ins);
    }

    private void setStuMap(List<Stu> stuList) {
        for (Stu stu : stuList)
            stuMap.put(stu.getUserId(), stu);
    }

    private void setTeacherMap(List<UserInfo> teacherList) {
        for (UserInfo userInfo : teacherList)
            teacherMap.put(userInfo.getUserName() + "_" + userInfo.getIdentityCard(), userInfo.getId());
    }

    private void setStudentMap(List<UserInfo> studentList) {
        for (UserInfo userInfo : studentList)
            studentMap.put(userInfo.getUserName() + "_" + userInfo.getIdentityCard(), userInfo.getId());
    }

    private void setFeijiMap(List<AirplaneNumber> feijiList) {
        for (AirplaneNumber feiji : feijiList)
            feijiMap.put(feiji.getPlaneNumber(), feiji);
    }

    private void setMonijiMap(List<AirplaneNumber> monijiList) {
        for (AirplaneNumber moniji : monijiList)
            monijiMap.put(moniji.getPlaneNumber(), moniji);
    }

    private void setAirportMap(List<Airport> airportList) {
        for (Airport airport : airportList)
            airportMap.put(airport.getIcao(), airport);
    }

    public int getCountRWS() {
        return dao.countRWS();
    }

    public int getCountNullJLDSN() {
        return dao.countNullJLDSN();
    }

    public int getCountJLDSN() {
        return dao.countJLDSN();
    }

    public List<String> listRwsSn(int start, int showNum) {
        return dao.pagerRWSSN(start, showNum);
    }

    public List<Integer> listJldFSSN(int start, int showNum) {
        return dao.pagerJldFSSN(start, showNum);
    }

    public List<String> listJldSN(int start, int showNum) {
        return dao.pagerJldSN(start, showNum);
    }

    public void saveTaskDoc(String rwsSn) {
        LOGGER.info("查询任务书编号(RWSSN): " + rwsSn);
        List<Rws> rwses = dao.listRwsByRwsSn(rwsSn);
        List<TaskDocDetails> taskDocDetailsList = new ArrayList<TaskDocDetails>(rwses.size());

        TaskDoc taskDoc = new TaskDoc();
        int flightTime = 0;
        int landingNum = 0;
        Long operateId = null;
        String taskDocNum = null;
        Long organizeId = null;
        String airplaneNumber = null;
        Date taskDocDate = null;
        Date createTime = null;
        Date operateTime = null;

        for (Rws rws : rwses) {
            TaskDocDetails taskDocDetails = new TaskDocDetails();

            taskDocDetails.setCreateTime(rws.getCreateTime());
            taskDocDetails.setAddTo(rws.getAddon() != 0);
            taskDocDetails.setVrille(rws.getSpin() != 0);
            taskDocDetails.setInstrument(rws.getIfr() != 0);
            taskDocDetails.setCutTo(rws.getXc() != 0);
            taskDocDetails.setCountTime(rws.getTotal());
            taskDocDetails.setEndTime(rws.getTto());
            taskDocDetails.setStartTime(rws.getTfrom());
//            taskDocDetails.setAirportByEndAirport(dao.getAirport(rws.getApto()));
//            taskDocDetails.setAirportByStartAirport(dao.getAirport(rws.getApfrom()));
            taskDocDetails.setAirportByEndAirport(airportMap.get(rws.getApto().toUpperCase()));
            taskDocDetails.setAirportByStartAirport(airportMap.get(rws.getApfrom().toUpperCase()));

            FlyBase flyBase = new FlyBase();
            flyBase.setId(Utils.getBaseId(rws.getBase()));
            taskDocDetails.setFlyBase(flyBase);

            UserBaseInfo leftUser = new UserBaseInfo();
            if (rws.getPf() > 0 && rws.getPf() < 500) {
//                Ins ins = dao.get(Ins.class, rws.getPf());
                Ins ins = insMap.get(rws.getPf());
//                leftUser.setId(dao.getUserBaseInfoId(ins.getTruename(), ins.getUsername(), (byte) 1));
                leftUser.setId(Long.parseLong(String.valueOf(teacherMap.get(ins.getTruename() + "_" + ins.getUsername()))));
                operateId = this.setOperateId(operateId, leftUser.getId());
            } else {
//                Stu stu = dao.get(Stu.class, rws.getPf());
                Stu stu = stuMap.get(rws.getPf());
//                leftUser.setId(dao.getUserBaseInfoId(stu.getTrueName(), stu.getUserName(), (byte) 2));
                leftUser.setId(Long.parseLong(String.valueOf(studentMap.get(stu.getTrueName() + "_" + stu.getUserName()))));
            }

            taskDocDetails.setUserBaseInfoByLeftUser(leftUser);
            taskDocDetails.setLeftCount(rws.getPfld());

            landingNum += taskDocDetails.getLeftCount();

            if (rws.getPnf() > 0 && rws.getPnf() < 500) {
//                Ins ins = dao.get(Ins.class, rws.getPnf());
                Ins ins = insMap.get(rws.getPnf());

                UserBaseInfo rightUser = new UserBaseInfo();
//                rightUser.setId(dao.getUserBaseInfoId(ins.getTruename(), ins.getUsername(), (byte) 1));
                rightUser.setId(Long.parseLong(String.valueOf(teacherMap.get(ins.getTruename() +
                                                                             "_" +
                                                                             ins.getUsername()))));
                operateId = this.setOperateId(operateId, rightUser.getId());

                taskDocDetails.setUserBaseInfoByRightUser(rightUser);
                taskDocDetails.setRightCount(rws.getPnfld().intValue());

                landingNum += taskDocDetails.getRightCount();
            } else if (rws.getPnf() > 10000) {
//                Stu stu = dao.get(Stu.class, rws.getPnf());
                Stu stu = stuMap.get(rws.getPnf());

                UserBaseInfo rightUser = new UserBaseInfo();
//                rightUser.setId(dao.getUserBaseInfoId(stu.getTrueName(), stu.getUserName(), (byte) 2));
                rightUser.setId(Long.parseLong(String.valueOf(studentMap.get(stu.getTrueName() +
                                                                             "_" +
                                                                             stu.getUserName()))));

                taskDocDetails.setUserBaseInfoByRightUser(rightUser);
                taskDocDetails.setRightCount(rws.getPnfld().intValue());

                landingNum += taskDocDetails.getRightCount();
            }


            if (rws.getDuty() > 0 && rws.getDuty() < 500) {
//                Ins ins = dao.get(Ins.class, rws.getDuty().intValue());
                Ins ins = insMap.get(rws.getDuty().intValue());

                UserBaseInfo dutyUser = new UserBaseInfo();
//                dutyUser.setId(dao.getUserBaseInfoId(ins.getTruename(), ins.getUsername(), (byte) 1));
                dutyUser.setId(Long.parseLong(String.valueOf(teacherMap.get(ins.getTruename() +
                                                                            "_" +
                                                                            ins.getUsername()))));
                operateId = this.setOperateId(operateId, dutyUser.getId());

                taskDocDetails.setUserBaseInfoByDutyTeacher(dutyUser);
            }

            if (rws.getThird() > 0 && rws.getThird() < 500) {
//                Ins ins = dao.get(Ins.class, rws.getThird());
                Ins ins = insMap.get(rws.getThird().intValue());

                UserBaseInfo crewUser = new UserBaseInfo();
//                crewUser.setId(dao.getUserBaseInfoId(ins.getTruename(), ins.getUsername(), (byte) 1));
                crewUser.setId(Long.parseLong(String.valueOf(teacherMap.get(ins.getTruename() +
                                                                            "_" +
                                                                            ins.getUsername()))));
                operateId = this.setOperateId(operateId, crewUser.getId());

                taskDocDetails.setUserBaseInfoByCrewUser(crewUser);
            }

            if (rws.getPffkind() != 0) {
                FlightCharacter leftC = flightCharacterMap.get(rws.getPffkind());
                taskDocDetails.setFlightCharacterByLeftCharacter(leftC);
            }

            if (rws.getPnffkind() != 0) {
                FlightCharacter rightC = flightCharacterMap.get(rws.getPnffkind());
                taskDocDetails.setFlightCharacterByRightCharacter(rightC);
            }

            if (rws.getThirdFkind() != 0) {
                FlightCharacter crewC = flightCharacterMap.get(rws.getThirdFkind());
                taskDocDetails.setFlightCharacterByCrewCharacter(crewC);
            }

            taskDocDetailsList.add(taskDocDetails);

            if (taskDocNum == null) {
                taskDocNum = rws.getRwssn();
            }

            Long oldOrg = Utils.getOrganizeId(String.valueOf(rws.getDadui()));
            if (organizeId == null) {
                organizeId = oldOrg;
            } else {
                if (!organizeId.equals(oldOrg)) {
                    LOGGER.warn("任务书存在不同的大队：任务书编号=" + rws.getRwssn() + ", 大队ID=" + organizeId + "，不同大队ID=" + oldOrg);
                }
            }

            if (airplaneNumber == null) {
                airplaneNumber = rws.getAcid();
            } else {
                if (!airplaneNumber.equals(rws.getAcid())) {
                    LOGGER.warn("任务书存在不同的飞机：任务书编号=" + rws.getRwssn() + ", 飞机编号=" + airplaneNumber + "，不同飞机编号=" + rws.getAcid());
                }
            }

            if (taskDocDate == null) {
                String docDate = DateUtils.dateToString(rws.getTfrom(), DateFormatEnum.YYYY_MM_DD);
                try {
                    taskDocDate = DateUtils.stringToDate(docDate, DateFormatEnum.YYYY_MM_DD);
                } catch (ParseException e) {
                    LOGGER.error("任务书日期转换错误!", e);
                }
            } else {
                String saveDocDate = DateUtils.dateToString(taskDocDate, DateFormatEnum.YYYY_MM_DD);
                String docDate = DateUtils.dateToString(rws.getTfrom(), DateFormatEnum.YYYY_MM_DD);
                if (!saveDocDate.equals(docDate)) {
                    LOGGER.warn("任务书存在不同的飞行日期：任务书编号=" + rws.getRwssn() + ", 飞行日期=" + saveDocDate + "，不同飞行日期=" + docDate);
                }
            }

            if (createTime == null) {
                createTime = rws.getCreateTime();
            } else {
                if (createTime.after(rws.getCreateTime())) {
                    createTime = rws.getCreateTime();
                }
            }

            if (operateTime == null) {
                operateTime = rws.getModifyTime();
            } else {
                if (operateTime.before(rws.getModifyTime())) {
                    operateTime = rws.getModifyTime();
                }
            }

            flightTime += rws.getTotal();
        }

        taskDoc.setFlightTime(flightTime);
        taskDoc.setLandingNum(landingNum);
        taskDoc.setTaskDocNum(taskDocNum);
        taskDoc.setCreateTime(createTime);
        taskDoc.setOperateTime(operateTime);
        taskDoc.setTaskDocDate(taskDocDate);

        Organize organize = new Organize();
        organize.setId(organizeId);
        taskDoc.setOrganize(organize);

        UserBaseInfo userBaseInfo = new UserBaseInfo();
        userBaseInfo.setId(operateId);

        taskDoc.setUserBaseInfoByCreaterId(userBaseInfo);
        taskDoc.setUserBaseInfoByOperatorId(userBaseInfo);

//        AirplaneNumber plane = dao.getAirplanNumber(airplaneNumber, (byte) 0);
        AirplaneNumber plane = feijiMap.get(airplaneNumber);
        taskDoc.setAirplaneNumber(plane);

        dao.save(taskDoc);

        for (TaskDocDetails taskDocDetails : taskDocDetailsList) {
            taskDocDetails.setTaskDoc(taskDoc);
            dao.save(taskDocDetails);
        }
    }

    private Long setOperateId(Long operateId, Long userId) {
        if (operateId != null) {
            if (userId != null && !operateId.equals(userId)) {
                LOGGER.warn("任务书/记录单 存在不同的教员：创建教员ID=" + operateId + ", 存在的不同教员ID=" + userId);
            }
        } else {
            operateId = userId;
        }

        return operateId;
    }

    public void saveSimulatorTaskDoc(String jldSn, boolean isFssn) {
        List<Jld> jldList = null;

        if (isFssn) {
            LOGGER.info("查询记录单编号(FSSN): " + jldSn);
            jldList = dao.listJLDByFSSN(jldSn);
        } else {
            LOGGER.info("查询记录单编号(JLDSN): " + jldSn);
            jldList = dao.listJLDByJLDSN(jldSn);
        }

        List<SimulatorTaskDocDetails> taskDocDetailsList = new ArrayList<SimulatorTaskDocDetails>(jldList.size());

        SimulatorTaskDoc simulatorTaskDoc = new SimulatorTaskDoc();
        Long operateId = null;
        String taskDocNum = null;
        Long organizeId = null;
        String airplaneNumber = null;
        Date taskDocDate = null;
        Date createTime = null;
        Date operateTime = null;
        int flightTime = 0;
        Boolean fullSimulator = null;

        for (Jld jld : jldList) {
            SimulatorTaskDocDetails simulatorTaskDocDetails = new SimulatorTaskDocDetails();

            simulatorTaskDocDetails.setCreateTime(jld.getCreateTime());
            simulatorTaskDocDetails.setAddTo(jld.getAddon() != 0);
            simulatorTaskDocDetails.setCountTime(jld.getTotal());
            simulatorTaskDocDetails.setStartTime(jld.getTfrom());
            simulatorTaskDocDetails.setEndTime(jld.getTto());
            simulatorTaskDocDetails.setLeftTrained(jld.getTraineePf() != 0);
            simulatorTaskDocDetails.setRightTrained(jld.getTraineePnf() != 0);

            if (jld.getPf() > 0 && jld.getPf() < 500) {
//                Ins ins = dao.get(Ins.class, jld.getPf());
                Ins ins = insMap.get(jld.getPf());

                UserBaseInfo leftUser = new UserBaseInfo();
//                leftUser.setId(dao.getUserBaseInfoId(ins.getTruename(), ins.getUsername(), (byte) 1));
                leftUser.setId(Long.parseLong(String.valueOf(teacherMap.get(ins.getTruename() + "_" + ins.getUsername()))));

                simulatorTaskDocDetails.setUserBaseInfoByLeftUser(leftUser);
            } else if (jld.getPf() > 10000) {
//                Stu stu = dao.get(Stu.class, jld.getPf());
                Stu stu = stuMap.get(jld.getPf());

                UserBaseInfo leftUser = new UserBaseInfo();
//                leftUser.setId(dao.getUserBaseInfoId(stu.getTrueName(), stu.getUserName(), (byte) 2));
                leftUser.setId(Long.parseLong(String.valueOf(studentMap.get(stu.getTrueName() + "_" + stu.getUserName()))));

                simulatorTaskDocDetails.setUserBaseInfoByLeftUser(leftUser);
            }

            if (jld.getPnf() > 0 && jld.getPnf() < 500) {
//                Ins ins = dao.get(Ins.class, jld.getPnf());
                Ins ins = insMap.get(jld.getPnf());

                UserBaseInfo rightUser = new UserBaseInfo();
//                rightUser.setId(dao.getUserBaseInfoId(ins.getTruename(), ins.getUsername(), (byte) 1));
                rightUser.setId(Long.parseLong(String.valueOf(teacherMap.get(ins.getTruename() +
                                                                             "_" +
                                                                             ins.getUsername()))));

                simulatorTaskDocDetails.setUserBaseInfoByRightUser(rightUser);
            } else if (jld.getPnf() > 10000) {
//                Stu stu = dao.get(Stu.class, jld.getPnf());
                Stu stu = stuMap.get(jld.getPnf());

                UserBaseInfo rightUser = new UserBaseInfo();
//                rightUser.setId(dao.getUserBaseInfoId(stu.getTrueName(), stu.getUserName(), (byte) 2));
                rightUser.setId(Long.parseLong(String.valueOf(studentMap.get(stu.getTrueName() +
                                                                             "_" +
                                                                             stu.getUserName()))));

                simulatorTaskDocDetails.setUserBaseInfoByRightUser(rightUser);
            }


            if (jld.getIns() > 0 && jld.getIns() < 500) {
//                Ins ins = dao.get(Ins.class, jld.getIns());
                Ins ins = insMap.get(jld.getIns());

                UserBaseInfo teacher = new UserBaseInfo();
//                teacher.setId(dao.getUserBaseInfoId(ins.getTruename(), ins.getUsername(), (byte) 1));
                teacher.setId(Long.parseLong(String.valueOf(teacherMap.get(ins.getTruename() +
                                                                           "_" +
                                                                           ins.getUsername()))));
                operateId = this.setOperateId(operateId, teacher.getId());

                simulatorTaskDocDetails.setUserBaseInfoByTeacherId(teacher);
            }

            taskDocDetailsList.add(simulatorTaskDocDetails);

            if (taskDocNum == null) {
                if (isFssn) {
                    taskDocNum = String.valueOf(jld.getFssn());
                } else {
                    taskDocNum = jld.getJldsn();
                }
            }

            Long oldOrg = Utils.getOrganizeId(String.valueOf(jld.getDadui()));
            if (organizeId == null) {
                organizeId = oldOrg;
            } else {
                if (!organizeId.equals(oldOrg)) {
                    if (isFssn) {
                        LOGGER.warn("记录单存在不同的大队：记录单编号(fssn)=" + jld.getFssn() + ", 大队ID=" + organizeId + "，不同大队ID=" + oldOrg);
                    } else {
                        LOGGER.warn("记录单存在不同的大队：记录单编号(jldsn)=" + jld.getJldsn() + ", 大队ID=" + organizeId + "，不同大队ID=" + oldOrg);
                    }
                }
            }

            if (airplaneNumber == null) {
                if (jld.getFsdid() != null) {
                    airplaneNumber = String.valueOf(jld.getFsdid());
                }
            } else {
                if (!airplaneNumber.equals(String.valueOf(jld.getFsdid()))) {
                    if (isFssn) {
                        LOGGER.warn("记录单存在不同的飞机：记录单编号(fssn)=" + jld.getFssn() + ", 飞机编号=" + airplaneNumber + "，不同飞机编号=" + String.valueOf(jld.getFsdid()));
                    } else {
                        LOGGER.warn("记录单存在不同的飞机：记录单编号(jldsn)=" + jld.getJldsn() + ", 飞机编号=" + airplaneNumber + "，不同飞机编号=" + String.valueOf(jld.getFsdid()));
                    }
                }
            }

            if (taskDocDate == null) {
                String docDate = DateUtils.dateToString(jld.getTfrom(), DateFormatEnum.YYYY_MM_DD);
                try {
                    taskDocDate = DateUtils.stringToDate(docDate, DateFormatEnum.YYYY_MM_DD);
                } catch (ParseException e) {
                    LOGGER.error("记录单日期转换错误!", e);
                }
            } else {
                String saveDocDate = DateUtils.dateToString(taskDocDate, DateFormatEnum.YYYY_MM_DD);
                String docDate = DateUtils.dateToString(jld.getTfrom(), DateFormatEnum.YYYY_MM_DD);
                if (!saveDocDate.equals(docDate)) {
                    if (isFssn) {
                        LOGGER.warn("记录单存在不同的飞行日期：记录单编号(fssn)=" + jld.getFssn() + ", 飞行日期=" + saveDocDate + "，不同飞行日期=" + docDate);
                    } else {
                        LOGGER.warn("记录单存在不同的飞行日期：记录单编号(jldsn)=" + jld.getJldsn() + ", 飞行日期=" + saveDocDate + "，不同飞行日期=" + docDate);
                    }
                }
            }

            if (createTime == null) {
                createTime = jld.getCreateTime();
            } else {
                if (createTime.after(jld.getCreateTime())) {
                    createTime = jld.getCreateTime();
                }
            }

            if (operateTime == null) {
                operateTime = jld.getModifyTime();
            } else {
                if (operateTime.before(jld.getModifyTime())) {
                    operateTime = jld.getModifyTime();
                }
            }

            flightTime += jld.getTotal();

            if (fullSimulator == null) {
                fullSimulator = jld.getFfs() != 0;
            } else {
                if (!fullSimulator.toString().equals(String.valueOf(jld.getFfs() != 0))) {
                    if (isFssn) {
                        LOGGER.warn("记录单模拟机是否全动不统一：记录单编号(fssn)=" + jld.getFssn() + ", 全动=" + fullSimulator + "，不同=" + String.valueOf(jld.getFfs() != 0));
                    } else {
                        LOGGER.warn("记录单模拟机是否全动不统一：记录单编号(jldsn)=" + jld.getJldsn() + ", 全动=" + fullSimulator + "，不同=" + String.valueOf(jld.getFfs() != 0));
                    }
                }
            }
        }

        simulatorTaskDoc.setFlightTime(flightTime);
        simulatorTaskDoc.setFullSimulator(fullSimulator);
        simulatorTaskDoc.setTaskDocNum(taskDocNum);
        simulatorTaskDoc.setCreateTime(createTime);
        simulatorTaskDoc.setOperateTime(operateTime);
        simulatorTaskDoc.setTaskDocDate(taskDocDate);

        Organize organize = new Organize();
        organize.setId(organizeId);
        simulatorTaskDoc.setOrganize(organize);

        UserBaseInfo userBaseInfo = new UserBaseInfo();
        userBaseInfo.setId(operateId);

        simulatorTaskDoc.setUserBaseInfoByCreaterId(userBaseInfo);
        simulatorTaskDoc.setUserBaseInfoByOperatorId(userBaseInfo);

        if (airplaneNumber != null) {
//            AirplaneNumber plane = dao.getAirplanNumber(airplaneNumber, (byte) 1);
            AirplaneNumber plane = monijiMap.get(airplaneNumber);
            simulatorTaskDoc.setAirplaneNumber(plane);
        }

        dao.save(simulatorTaskDoc);

        for (SimulatorTaskDocDetails taskDocDetails : taskDocDetailsList) {
            taskDocDetails.setSimulatorTaskDoc(simulatorTaskDoc);
            dao.save(taskDocDetails);
        }
    }

    public void listErrorFsSn() throws IOException {
        List<String> errorList = Utils.readErrorFile("D:\\fsSnError");
        Set<Integer> idSet = new HashSet<Integer>();
        for (String fsSn : errorList) {
            List<Jld> jldList = dao.listJLDByFSSN(fsSn);
            for (Jld jld : jldList) {
                idSet.add(jld.getPf());
                idSet.add(jld.getPnf());
                idSet.add(jld.getIns());
            }
        }

        for (Integer id : idSet) {
            if (id > 0 && id < 500) {
                Ins ins = insMap.get(id);
                System.out.println("ins:" + id);
                System.out.println("SELECT ID, USER_NAME, IDENTITY_CARD FROM USER_BASE_INFO WHERE USER_NAME = '" + ins.getTruename() + "' AND IDENTITY_CARD = '" + ins.getUsername() + "';");
            } else if (id > 10000) {
                Stu stu = stuMap.get(id);
                System.out.println("stu:" + id);
                System.out.println("SELECT ID, USER_NAME, IDENTITY_CARD FROM USER_BASE_INFO WHERE USER_NAME = '" + stu.getTrueName() + "' AND IDENTITY_CARD = '" + stu.getUserName() + "';");
            }
        }
    }

    public void listErrorJldSn() throws IOException {
        List<String> errorList = Utils.readErrorFile("D:\\jldSnTwo");
        Set<Integer> idSet = new HashSet<Integer>();
        for (String jldSn : errorList) {
            List<Jld> jldList = dao.listJLDByJLDSN(jldSn);
            for (Jld jld : jldList) {
                idSet.add(jld.getPf());
                idSet.add(jld.getPnf());
                idSet.add(jld.getIns());
            }
        }

        for (Integer id : idSet) {
            if (id > 0 && id < 500) {
                Ins ins = insMap.get(id);
                System.out.println("ins:" + id);
                System.out.println("SELECT ID, USER_NAME, IDENTITY_CARD FROM USER_BASE_INFO WHERE USER_NAME = '" + ins.getTruename() + "' AND IDENTITY_CARD = '" + ins.getUsername() + "';");
            } else if (id > 10000) {
                Stu stu = stuMap.get(id);
                System.out.println("stu:" + id);
                System.out.println("SELECT ID, USER_NAME, IDENTITY_CARD FROM USER_BASE_INFO WHERE USER_NAME = '" + stu.getTrueName() + "' AND IDENTITY_CARD = '" + stu.getUserName() + "';");
            }
        }
    }

    public void listErrorRwsSn() throws IOException {
        List<String> errorList = Utils.readErrorFile("D:\\rwsSnTwo");
        Set<Integer> idSet = new HashSet<Integer>();
        for (String rwsSn : errorList) {
            List<Rws> rwsList = dao.listRwsByRwsSn(rwsSn);
            for (Rws rws : rwsList) {
                idSet.add(rws.getPf());
                idSet.add(rws.getPnf());
                idSet.add(rws.getThird().intValue());
                idSet.add(rws.getDuty().intValue());
            }
        }

        for (Integer id : idSet) {
            if (id > 0 && id < 500) {
                Ins ins = insMap.get(id);
                System.out.println("ins:" + id);
                System.out.println("SELECT ID, USER_NAME, IDENTITY_CARD FROM USER_BASE_INFO WHERE USER_NAME = '" + ins.getTruename() + "' AND IDENTITY_CARD = '" + ins.getUsername() + "';");
            } else if (id > 10000) {
                Stu stu = stuMap.get(id);
                System.out.println("stu:" + id);
                System.out.println("SELECT ID, USER_NAME, IDENTITY_CARD FROM USER_BASE_INFO WHERE USER_NAME = '" + stu.getTrueName() + "' AND IDENTITY_CARD = '" + stu.getUserName() + "';");
            }
        }
    }
}
